package com.dao;

import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.model.Member;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.tools.ConnDB;

public class MemberDaoImpl implements MemberDao {

	private ConnDB conn=new ConnDB();
	@Override
	public int Insert(Member m) {
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time=dateFormat.format(now);
		time="'"+time+"'";
		String sql="insert into user(username,email,phone,password,addtime)"
				+" values('"+m.getUsername()+"','"+m.getEmail()+"','"+m.getTel()+"','"+m.getPwd()+"',"+time+")";
		int row=conn.executeUpdate(sql);
		return row;
	}

	@Override
	public List Select() {
		Member form = null;
		List list=new ArrayList();
		return list;
	}

	@Override
	public int Update(Member m) {
		String sql="update user set username='"+m.getUsername()+"',password='"+m.getPwd()+"',email='"+m.getEmail()+"',phone='"+
	               m.getTel()+"' where id="+m.getID();
		int row=conn.executeUpdate(sql);
		return row;
	}
}
